﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using LGE;
using System.IO;

namespace Thaneros
{
    public class BlockManager
    {
        PlayScreen ps;
        public Block block = new Block();

        // Tile Codes
        const int spikeCode = 93;
        const int geiserCode = 94;
        const int crystalCode = 95;
        const int flagCode = 96;

        public BlockManager(PlayScreen ps)
        {
            this.ps = ps;
            Tile.UndergroundCode = 0;
            //Block.checkCodeActions.Add(crystalCode, delegate(Block b, Point p) { ps.c.crystals++; ps.crystalsInThisSession++; b.map[1][p.Y][p.X] = 0; Audio.PlaySFX(ps.c.SFX_Crystal); });
            LoadBlock();
        }

        public void Update(GameTime gameTime)
        {
        }

        public void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            Vector2 relPos = ps.c.position - ps.c.drawPosition;
            block.Draw(spriteBatch, gameTime, 0, relPos);
            block.Draw(spriteBatch, gameTime, 1, relPos);
            //block.DrawUnderground(spriteBatch, relPos);
        }

        public void DrawForeground(SpriteBatch spriteBatch, GameTime gameTime)
        {
            Vector2 relPos = ps.c.position - ps.c.drawPosition;
            block.Draw(spriteBatch, gameTime, 2, relPos);
        }

        public void LoadBlock()
        {
            block = new Block(Vector2.Zero, "Content\\Blocks\\0.block");

            for (int i = 0; i < Block.Height; ++i)
                for (int j = 0; j < Block.Width; ++j)
                {
                    for (int k = 0; k < 3; ++k)
                    {
                        if (block.map[k][i][j] == geiserCode) { break; }
                    }
                }
        }

        // Collision
        public float CollisionV(EngineObject obj, bool isUp, bool checkCodes)
        {
            return isUp ? block.CollisionUp(obj, checkCodes) : block.CollisionDown(obj, checkCodes);
        }

        public float CollisionH(EngineObject obj, bool isLeft, bool checkCodes)
        {
            return isLeft ? block.CollisionLeft(obj, checkCodes) : block.CollisionRight(obj, checkCodes);
        }
    }
}
